//
//  AddViewController.m
//  HJZWeiBo
//
//  Created by lanou on 16/5/28.
//  Copyright © 2016年 蒋晨成. All rights reserved.
//

#import "AddViewController.h"

@interface AddViewController ()



@end

@implementation AddViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.addView = [[AddView alloc]initWithFrame:CGRectMake((kWidth - 180) / 3, kHeight / 2 - 60, kWidth - 2 * (kWidth - 180) / 3, 190)];
    
    self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0 , kWidth, kHeight)];
    [self.view addSubview:_scrollView];
    
//    self.addView = [[AddView alloc]initWithFrame:CGRectMake((kWidth - 180) / 3, kHeight , kWidth - 2 * (kWidth - 180) / 3, 190)];
//    self.addView.alpha = 0;
    
    self.left = [[SmallView alloc]initWithFrame:CGRectMake((kWidth - 180) / 3, kHeight - 60, 60, 200)];
    [self.view addSubview:_left];
    
    self.middle = [[SmallView alloc]initWithFrame:CGRectMake(kWidth / 2 - 30, kHeight - 60, 60, 200)];
    [self.view addSubview:_middle];
    self.middle.button.backgroundColor = [UIColor orangeColor];
    [self.middle.button setImage:[UIImage imageNamed:@"zhaopian"] forState:UIControlStateNormal];
    self.middle.label.text = @"照片/视频";
    self.middle.button2.backgroundColor = [UIColor blueColor];
    [self.middle.button2 setImage:[UIImage imageNamed:@"dianping"] forState:UIControlStateNormal];
    self.middle.label2.text = @"点评";
    
    self.right = [[SmallView alloc]initWithFrame:CGRectMake(kWidth - (kWidth - 180) / 3 - 60, kHeight - 60, 60, 200)];
    [self.view addSubview:_right];
    self.right.button.backgroundColor = [UIColor yellowColor];
    [self.right.button setImage:[UIImage imageNamed:@"toutiao"] forState:UIControlStateNormal];
    self.right.label.text = @"头条文章";
    self.right.button2.backgroundColor = [UIColor cyanColor];
    [self.right.button2 setImage:[UIImage imageNamed:@"gengduo"] forState:UIControlStateNormal];
    self.right.label.text = @"更多";
    
    self.cancleButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.cancleButton.frame = CGRectMake(0, kHeight - 50, kWidth, 50);
    self.cancleButton.backgroundColor = [UIColor whiteColor];
    [self.cancleButton setTitle:@"X" forState:UIControlStateNormal];
    [self.cancleButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [self.cancleButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.scrollView addSubview:self.cancleButton];
    
    [self performSelector:@selector(changeAction:) withObject:_left afterDelay:.1];
    [self performSelector:@selector(action2:) withObject:_middle afterDelay:.2];
    [self performSelector:@selector(change:) withObject:_right afterDelay:.3];
    self.left.alpha = .3;
    self.middle.alpha = .3;
    self.right.alpha = .3;
    self.view.backgroundColor = PKCOLOR(240, 240, 240);
    
    
    
    
    // Do any additional setup after loading the view.
}

- (void)buttonAction:(UIButton *)button{
    [self dismissAction];
    [self performSelector:@selector(dismissMiddle) withObject:nil afterDelay:0.1];
    [self performSelector:@selector(dismissLeft) withObject:nil afterDelay:0.2];
    [self performSelector:@selector(dismiss) withObject:nil afterDelay:0.5];
    
}
- (void)dismiss{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)dismissMiddle{
    [UIView animateWithDuration:0.4 animations:^{
        self.middle.frame = CGRectMake(kWidth / 2 - 30, kHeight, 60, 200);
        self.middle.alpha = 0;
    }];
}

- (void)dismissLeft{
    [UIView animateWithDuration:0.3 animations:^{
        self.left.frame = CGRectMake((kWidth - 180) / 3, kHeight, 60, 200);
        self.left.alpha = 0;
    }];
}

- (void)dismissAction{
    [UIView animateWithDuration:0.5 animations:^{
        self.right.frame = CGRectMake(kWidth - (kWidth - 180) / 3 - 60, kHeight, 60, 200);
        self.right.alpha = 0;
    }];
    
}

- (void)change:(UIView *)view{
    [UIView animateWithDuration:0.3 animations:^{
        view.frame = CGRectMake(kWidth - (kWidth - 180) / 3 - 60, kHeight / 2 - 60, kWidth - 2 * (kWidth - 180) / 3, 190);
        view.alpha = 0.8;
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:.3 animations:^{
            view.frame = CGRectMake(kWidth - (kWidth - 180) / 3 - 60, kHeight / 2 - 40, kWidth - 2 * (kWidth - 180) / 3, 190);
        }];
        view.alpha = 1.0;
    }];
}

- (void)action2:(UIView *)view{
   [UIView animateWithDuration:0.3 animations:^{
       view.frame = CGRectMake(kWidth / 2 - 30, kHeight / 2 - 60, kWidth - 2 * (kWidth - 180) / 3, 190);
       view.alpha = 0.8;
   } completion:^(BOOL finished) {
       [UIView animateWithDuration:.3 animations:^{
           view.frame = CGRectMake(kWidth / 2 - 30, kHeight / 2 - 40, kWidth - 2 * (kWidth - 180) / 3, 190);
           view.alpha = 1.0;
       }];
   }];
    
}

     

- (void)changeAction:(UIView *)view {
    [UIView animateWithDuration:0.3 animations:^{
        view.frame = CGRectMake((kWidth - 180) / 3, kHeight / 2 - 60, kWidth - 2 * (kWidth - 180) / 3, 190);
        view.alpha = 0.8;
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.3 animations:^{
            view.frame = CGRectMake((kWidth - 180) / 3, kHeight / 2 - 40, kWidth - 2 * (kWidth - 180) / 3, 190);
            view.alpha = 1.0;
        }];
    }];
//    [UIView animateWithDuration:1 animations:^{
//        self.addView.view1.frame = CGRectMake((kWidth - 180) / 3, kHeight / 2, kWidth - 2 * (kWidth - 180) / 3, 190);
//                self.addView.alpha = 1.0;
//    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
